import {
  CallLogsApi,
} from "../../common/apis/callLogs";
import {
  createStoreBindings
} from "mobx-miniprogram-bindings";
import {
  SUB_PAGES
} from "../../config/router.config";
import {
  getElHeightRpx,
} from "../../utils/dom"
import {
  callLogsFilterStore
} from '../../store/callLogsFilterStore'
const app = getApp()

// pagesCallLogs/callLogs.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    bodyHeight: 0,
    dataList: [],
    keywords: ''
  },
  onFilter() {
    wx.navigateTo({
      url: SUB_PAGES.CallLogs.FILTER.router,
    })
  },
  changeSearch: wx.$_.debounce(function ({
    detail
  }) {
    this.data.keywords = detail.value
    this.init()
  }, 300),
  init() {
    const self = this
    getElHeightRpx('#callLogsHeader', (height) => {
      self.setData({
        bodyHeight: app.globalData.viewHeight - height
      })
    })
    this.initData()

  },
  initData() {
    const self = this
    const {
      dealType,
      deptIdList,
      endTime,
      startTime,
      type,
      receptionList
    } = this.data
    const queryData = {
      dealType,
      deptIdList,
      endTime,
      startTime,
      type,
      receptionList,
      phone: this.data.keywords
    }
    CallLogsApi.getCallLogsList(queryData, (res) => {
      self.setData({
        dataList: res.data.rows || []
      })
    })
  },
  // 滚动底部触发
  onScrollBottom() {
    console.log('onScrollBottom');
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    this.sotreBind = createStoreBindings(this, {
      store: callLogsFilterStore,
      fields: ["dealType", "deptIdList", "endTime", "phone", "receptionList", "startTime", "type"],

    })
    this.sotreBind.updateStoreBindings()
    this.init()
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {
    this.sotreBind.destroyStoreBindings();
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})